﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraControll : MonoBehaviour {
    //拖拽移动速度
    public float speed;
    GameObject player;
    float mouseX;
    float mouseY;
	void Start () {
        player = GameObject.FindWithTag("EditorOnly");
        //Debug.Log("player" + player.name);
	}
	
	// Update is called once per frame
	void Update () {
        MoveVisualAngel();
        CameraScaleChange();
	}
    //拖拽改变视角
    void MoveVisualAngel()
    {
        if (Input.GetMouseButton(1))
        {
            mouseX = Input.GetAxis("Mouse X");
            mouseY = Input.GetAxis("Mouse Y");
            transform.RotateAround(player.transform.position, player.transform.up, mouseX * speed * Time.deltaTime);
            transform.RotateAround(player.transform.position, player.transform.up, mouseY * speed * Time.deltaTime);
        }
    }

    //缩放改变相机size
    void CameraScaleChange()
    {

        if (Input.GetAxis("Mouse ScrollWheel") < 0)
        {
            if (Camera.main.fieldOfView <= 100)
                Camera.main.fieldOfView += 2;
            if (Camera.main.orthographicSize <= 20)
                Camera.main.orthographicSize += 0.5F;
        }
        //Zoom in
        if (Input.GetAxis("Mouse ScrollWheel") > 0)
        {
            if (Camera.main.fieldOfView > 2)
                Camera.main.fieldOfView -= 2;
            if (Camera.main.orthographicSize >= 1)
                Camera.main.orthographicSize -= 0.5F;
        }
    }
}
